package com.midele.goodstuff.ui.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun LeftIconTextRow(
    iconId: Int,
    text: String,
    textSize: TextUnit = 14.sp,
    textWeight: FontWeight = FontWeight.Normal,
    textColor: androidx.compose.ui.graphics.Color,
    modifier: Modifier = Modifier,
    iconSize: Dp = 24.dp,
    spacing: Dp = 4.dp,
    contentDescription: String? = null, // For accessibility
    onClick: (() -> Unit)? = null
) {
    Row(
        modifier = if (onClick != null) {
            modifier.clickable(onClick = onClick)
        } else {
            modifier
        },
        verticalAlignment = Alignment.CenterVertically, // 垂直居中对齐图标和文字
        horizontalArrangement = Arrangement.Center // 水平方向从左到右排列
    ) {
        Image(
            painter = painterResource(id = iconId),
            contentDescription = contentDescription, // Important for accessibility
            modifier = Modifier.size(iconSize)
        )
        Spacer(modifier = Modifier.width(spacing)) // 图标和文字之间的间距
        Text(
            text = text,
            fontSize = textSize,
            color = textColor,
            fontWeight = textWeight
        )
    }
}